import unittest
import requests


class TestIhrmLogin(unittest.TestCase):
    def test01_login_ok(self):
        resp = requests.post(url="http://ihrm-test.itheima.net/api/sys/login",
                             json={"mobile": "13800000002", "password": "123456"})
        print(resp.json())
        self.assertEqual(200, resp.status_code)
        self.assertEqual(True, resp.json().get("success"))
        self.assertEqual(10000, resp.json().get("code"))
        self.assertIn("操作成功", resp.json().get("message"))

    def test02_tel_not_exists(self):
        resp = requests.post(url="http://ihrm-test.itheima.net/api/sys/login",
                             json={"mobile": "13856982002", "password": "123456"})
        print(resp.json())
        self.assertEqual(200, resp.status_code)
        self.assertEqual(False, resp.json().get("success"))
        self.assertEqual(20001, resp.json().get("code"))
        self.assertIn("用户名或密码错误", resp.json().get("message"))

    def test03_pwd_error(self):
        resp = requests.post(url="http://ihrm-test.itheima.net/api/sys/login",
                             json={"mobile": "13800000002", "password": "12345678"})
        print(resp.json())
        self.assertEqual(200, resp.status_code)
        self.assertEqual(False, resp.json().get("success"))
        self.assertEqual(20001, resp.json().get("code"))
        self.assertIn("用户名或密码错误", resp.json().get("message"))
